package com.czh.auth.domain.service.impl;

import com.czh.auth.domain.convert.AuthRolePermissionDomainConverter;
import com.czh.auth.domain.entity.AuthRolePermissionBO;
import com.czh.auth.domain.service.AuthRolePermissionDomainService;
import com.czh.auth.infra.basic.entity.AuthRolePermission;
import com.czh.auth.infra.basic.service.AuthRolePermissionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author caozaihui
 * @version 1.0
 * @since 2024/8/30 下午 10:06
 */
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {

    @Resource
    private AuthRolePermissionService authRolePermissionService;
    @Override
    public Boolean addAuthRolePermission(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission> authRolePermissionList = new LinkedList<>();
        Long roleId = authRolePermissionBO.getRoleId();
        authRolePermissionBO.getPermissionIdList().forEach(permissionId->{
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermissionList.add(authRolePermission);
        });
        return authRolePermissionService.insertBatch(authRolePermissionList)>0;
    }
}
